﻿/// <reference path="D:\PROJECTS\eking\Modules\Orchard.jQuery\Scripts\jquery-1.6.4.min.js" />

$.fn.jSelectable = function (options) {
    var opts = $.extend({}, $.fn.jSelectable.defaults, options);

    selectableHandler = function (input) {
        var obj = input;
        var currentSelected = undefined;
        obj.children().addClass('ui-selectee');
        if (opts.selectmode == 'click') {
            obj.children().click(function () {
                selectItem(this);
            });
        }
        if (opts.selectmode == 'dblclick') {
            obj.children().dblclick(function () {
                selectItem(this);
            });
        }

        function selectItem(input) {
            obj.children().removeClass('ui-selected');
            $(input).addClass('ui-selected');
            if (opts.onselected != undefined)
                opts.onselected(obj, input);
        }
    }


    return this.each(function () {
        new selectableHandler($(this));
    });


}


$.fn.jSelectable.defaults = {
    selectmode: 'click',
    onselected: undefined
}